﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ERP.Manager.Core;
using ERP.Manager.DataEntity;
using ERP.Manager.DataProvider;
using ERP.Manager.DataHelper;
using System.Data.SqlClient;
using System.Data;
namespace ERP.Manager.SQLServerProvider
{
    public class ECS_brandinfoRepository : IECS_brandinfoRepository
    {
        #region 分页查询所有商品品牌信息
        public List<ECS_brandinfo> all_getcs_brandinfo_page(int pagecount)
        {
            List<ECS_brandinfo> list = new List<ECS_brandinfo>();
            SqlDataReader read = SQLHelper.ExecuteReader(CommandType.Text, ERPSQL.ALL_GETECS_BRANDINFO_PAGE,
                new SqlParameter("@pagecount", pagecount));
            try
            {
                while (read.Read())
                {
                    ECS_brandinfo brand = new ECS_brandinfo();
                    brand.brand_id = int.Parse(read["brand_id"].ToString());
                    brand.brand_name = read["brand_name"].ToString();
                    brand.brand_logo = read["brand_logo"].ToString();
                    brand.brand_desc = read["brand_desc"].ToString();
                    brand.site_url = read["site_url"].ToString();
                    brand.sort_order = int.Parse(read["sort_order"].ToString());
                    brand.is_show = int.Parse(read["is_show"].ToString());
                    list.Add(brand);
                }
                read.Close();
            }
            catch (Exception)
            {
                read.Close();
            }
            finally
            {
                read.Dispose();
            }
            return list;
        }
        #endregion

        #region 查询所有商品品牌信息
        public List<ECS_brandinfo> all_ecs_brandinfo()
        {
            List<ECS_brandinfo> list = new List<ECS_brandinfo>();
            SqlDataReader read = SQLHelper.ExecuteReader(CommandType.Text, ERPSQL.ALL_ECS_BRANDINFO);
            try
            {
                while (read.Read())
                {
                    ECS_brandinfo brand = new ECS_brandinfo();
                    brand.brand_id = int.Parse(read["brand_id"].ToString());
                    brand.brand_name = read["brand_name"].ToString();
                    brand.brand_logo = read["brand_logo"].ToString();
                    brand.brand_desc = read["brand_desc"].ToString();
                    brand.site_url = read["site_url"].ToString();
                    brand.sort_order = int.Parse(read["sort_order"].ToString());
                    brand.is_show = int.Parse(read["is_show"].ToString());
                    list.Add(brand);
                }
                read.Close();
            }
            catch (Exception)
            {
                read.Close();
            }
            finally
            {
                read.Dispose();
            }
            return list;
        }
        #endregion

        #region 添加商品品牌信息
        public int add_ecs_brandinfo(ECS_brandinfo brand)
        {
            int rowcount = SQLHelper.ExecuteNonQuery(CommandType.Text, ERPSQL.ADD_ECS_BRANDINFO,
                new SqlParameter("@brand_name", brand.brand_name),
                new SqlParameter("@brand_logo", brand.brand_logo),
                new SqlParameter("@brand_desc", brand.brand_desc),
                new SqlParameter("@site_url", brand.site_url),
                new SqlParameter("@sort_order", brand.sort_order),
                new SqlParameter("@is_show", brand.is_show));
            return rowcount;
        }
        #endregion

        #region 修改商品品牌信息
        public int update_ecs_brandinfo(ECS_brandinfo brand)
        {
            int rowcount = SQLHelper.ExecuteNonQuery(CommandType.Text, ERPSQL.UPDATE_ECS_BRANDINFO,
                new SqlParameter("@brand_name", brand.brand_name),
                new SqlParameter("@brand_logo", brand.brand_logo),
                new SqlParameter("@brand_desc", brand.brand_desc),
                new SqlParameter("@site_url", brand.site_url),
                new SqlParameter("@sort_order", brand.sort_order),
                new SqlParameter("@is_show", brand.is_show),
                new SqlParameter("@brand_id", brand.brand_id));
            return rowcount;
        }
        #endregion

        #region 删除商品品牌信息
        public int delete_ecs_brandinfo(int brand_id)
        {
            int rowcount = SQLHelper.ExecuteNonQuery(CommandType.Text, ERPSQL.DELETE_ECS_BRANDINFO, new SqlParameter("@brand_id", brand_id));
            return rowcount;
        }
        #endregion

        #region 修改商品的显示状态
        public int update_ecs_brand_is_show(int brand_id, int is_show)
        {
            int rowcount = SQLHelper.ExecuteNonQuery(CommandType.Text, ERPSQL.UPDATE_ECS_BRAND_IS_SHOW,
                new SqlParameter("@is_show", is_show),
                new SqlParameter("@brand_id", brand_id));
            return rowcount;
        }
        #endregion
    }
}
